home *** CD-ROM | disk | FTP | other *** search
- Path: inforamp.net!ts44-07
- From: rmorin@inforamp.net (Randy Charles Morin)
- Newsgroups: comp.lang.c
- Subject: Re: How can I have 2 instances of a program write appending to a file?
- Date: Fri, 02 Feb 96 18:13:16 GMT
- Organization: MiddleWorld SoftWare
- Message-ID: <4etjtu$7s1@sam.inforamp.net>
- References: <9601311707.AA04679@cae1-5.agt.gmeds.com>
- NNTP-Posting-Host: ts44-07.tor.inforamp.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <9601311707.AA04679@cae1-5.agt.gmeds.com>,
- "David S. Pesetsky 230-6088 AGT/8880" <iedsp@agt.gmeds.com> wrote:
- >Platform: IBM RISC6000 AIX3.2.5 X11R5
- >
- >I need to make a c-program that can append strings to one file without
- >interfering with other instances of that program which are running. In other
- >words, I need it to check if the file is open, if it is, wait until it's
- available, then
- >write to it. I don't want to mess with process id's. Can I do it?
- >
- >Please e-mail your response to me 'cause I can't receive USENET. Thanks.
- >
- >Dave
-
- I'll just paste in an example that I use.
- Some of the code might not be compatible with your platform.
-
- ----------------------------------------------------------------------
- time_t StartTime=time(NULL);
-
- while ((hFile=sopen(cszFilename, O_RDWR | O_BINARY, SH_DENYRW)) == -1)
- {
- if (dwStatus) *dwStatus = FALSE;
- if (StartTime+60>time(NULL)) break;
- /* When this function returns dwStatus=FALSE
- an error should be reported
- and execution should be terminated */
- }
-
- if (hFile!=-1)
- if (dwStatus) *dwStatus = TRUE;
- ----------------------------------------------------------------------
-
- Using sopen is the key to the whole thing.
- I think sopen is in most of the standard libraries.
-
- Agrivar
-